package com.haha.action;

import com.accp.biz.BookBiz;
import com.accp.biz.PublisherBiz;
import com.accp.biz.categoryBiz;
import com.accp.info.Books;
import com.accp.where.BookWhere;
import com.haha.hibernate.Page;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BookAction extends ActionSupport {

	private BookWhere bw;
	private int pageSize;
	private int pageIndex;

	private BookBiz bookBiz = new BookBiz();
	private categoryBiz categoryBiz = new categoryBiz();
	private PublisherBiz publisherBiz = new PublisherBiz();

	public BookWhere getBw() {
		return bw;
	}

	public void setBw(BookWhere bw) {
		this.bw = bw;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public String execute() {
		if (bw == null) {

			bw = new BookWhere();

		}
		if (bw.getOrderby() == null || bw.getOrderby().length() == 0) {

			bw.setOrderby("id");

		}

		if (pageSize == 0) {
			pageSize = 10;

		}
		bw.procPrice();
		Page<Books> page = new Page<Books>(pageSize);
		page.setPageNo(pageIndex);

		bookBiz.findBookByWhereAndPage(bw, page);

		ActionContext ac = ActionContext.getContext();
		ac.put("books", page.getResult());
		ac.put("pg", page);
		ac.put("nav", page.makeJsNav("gotoPage"));
		ac.put("cats", categoryBiz.findAll());
		ac.put("pubs", publisherBiz.findAll());

		return SUCCESS;
	}
}